import Vue from 'vue'
import services from './services'


function servicesDelegete(options) {
    this.forEachServices(options)
}

servicesDelegete.prototype.forEachServices = function (options) {
    var keys = Object.keys(options)
    keys.forEach(key => {
        let items = options[key]
        let itemsKeys = Object.keys(items)
        itemsKeys.forEach(itemKey => {
            this.proxy(key, itemKey)
        })
    })
}
servicesDelegete.prototype.proxy = function (sourceKey, key) {
    Object.defineProperty(this, key, {
        get() {
            return services[sourceKey][key]
        },
        // set(val) {
        //     services[sourceKey][key] = val;
        // }
    });

}
export default {
    install(Vue) {
        Object.defineProperty(Vue.prototype, '$service', {
            value: new servicesDelegete(services)
        })
    }
}



